/*
 * Copyright (c) 2006 - 2022, webrx.cn All rights reserved.
 *
 */
package cn.webrx;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;


/**
 * <p>Project: app2022 - Ex4
 * <p>Powered by webrx On 2022-01-18 14:25:37
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class Ex4 {
    public static void main(String[] args) {
        String file = "C:\\app2022\\08io\\src\\main\\java\\cn\\webrx\\Ex4.java";
        try (var f = new BufferedReader(new FileReader(file))) {
            int num = 0; //总行数
            int ss = 0; //空行
            int mm = 0; //注释行
            while (f.ready()) {
                String line = f.readLine();
                ++num;
                if (line.trim().length() == 0) {
                    ++ss;
                }
                if (line.trim().matches("(/\\*|\\*|//).*") || line.trim().matches(".*//[a-zA-Z_0-9\\u4e00-\\u9fa5\\s]*$")) {
                    System.out.println(line);
                    ++mm;
                }
                //System.out.printf("%02d、%s%n", ++num, line);
            }
            //System.out.println(num);
            System.out.printf("总行数：%d行，空行：%d行，注释行：%d行。%n", num, ss, mm);

            //文件总行数
            //System.out.println(f.lines().count());

            //空行总数
            //long n1 = f.lines().filter(e -> e.trim().length() == 0).count();
            //System.out.println(n1);

            //注释行总数
            //long n2 = f.lines().filter(e -> e.trim().matches("(/\\*|\\*|//).*")).count();
            //System.out.println(n2);

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
